package com.edu.gcu.manager.controller;

import com.edu.gcu.manager.service.IDealerService;
import com.edu.gcu.system.common.Const;
import com.edu.gcu.system.common.ResponseCode;
import com.edu.gcu.system.common.ServerResponse;
import com.edu.gcu.system.pojo.Admin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @author polo
 * @version V1.0
 * @description: 后台经销商控制器
 * @date 2018-02-20-12:09
 */

@Controller
@RequestMapping("/manage/dealer")
public class DealerManageController {


    private static Logger logger = LoggerFactory.getLogger(DealerManageController.class);

    @Autowired
    private IDealerService iDealerService;

    /**
     * @description 用户列表
     * @author polo
     */
    @ResponseBody
    @RequestMapping("userList.do")
    public ServerResponse userList(@RequestParam(value = "nickname", defaultValue = "") String nickname,
                                   @RequestParam(value = "orderBy", required = false) String orderBy,
                                   @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpSession session) {
        Admin currentAdmin = (Admin) session.getAttribute(Const.CURRENT_ADMIN);
        if (currentAdmin == null) {
            return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(), ResponseCode.NEED_LOGIN
                    .getDesc());
        }
        return iDealerService.userList(nickname, orderBy, pageNum, pageSize);
    }
}
